<template>
  <div class="home-page body">
    <van-tabs animated v-model="activeIndex">
      <van-tab v-for="channel in channelList" :title="channel.name" :key="channel.id">
        <!--
       文章列表组件
        -->
        <article-list :cid="channel.id"></article-list>
      </van-tab>
    </van-tabs>
    <!-- 按钮 -->
    <div class="btn-wrapper">
      <geek-icon name="search"></geek-icon>
      <geek-icon @click.native="isShow=true" name="channel"></geek-icon>
    </div>

    <!-- 频道的组件  -->
    <!-- <article-channel @update:activeIndex="setActiveIndex" :activeIndex="activeIndex" :myChannels="channelList" v-model="isShow"></article-channel> -->
    <article-channel :activeIndex.sync="activeIndex" :myChannels="channelList" v-model="isShow"></article-channel>
  </div>
</template>

<script>
import { getMyChannels } from '@/api/home'
import articleList from './components/article-list.vue'
import articleChannel from './components/article-channel.vue'
export default {
  name: 'Home',
  data () {
    return {
      activeIndex: 1,
      channelList: [],
      isShow: false
    }
  },
  components: {
    articleList,
    articleChannel
  },
  methods: {
    // setActiveIndex (index) {
    //   console.log('传递过来的索引值:', index)

    //   this.activeIndex = index
    // },
    async getMyChannels () {
      const data = await getMyChannels()
      // console.log(data.data.data)
      this.channelList = data
    }
  },
  created () {
    this.getMyChannels()
    // request
    // request({
    //   url: 'channels'
    // })
    // 语义化明显，而且将网络请求进行分层。

    // 如果已经用await-to-js d 处理了，那么返回的数据 []
    // const [err, data] = await getAllChannels()
    // // vantUI
    // if (err) return this.$toast.fail(err)
    // console.log(data)
  }
}
</script>
<style scoped lang="less">
// 你修改的都是vantUI里面的样式，必须得穿透
// /deep/ ::v-deep >>>
/deep/ .van-tabs {
  height: 100%;
  display: flex;
  flex-direction: column;
  .van-tabs__line {
    background: @geek-color;
    height: 2px;
    width: 32px;
  }
  .van-tab {
    color: #9EA1AE;
  }
  .van-tab--active {
    font-size: 18px;
    color: #333;
  }
  .van-tabs__wrap {
    padding-right: 86px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
  }
  .van-tabs__content {
    flex: 1;
    overflow: hidden;
  }
  .van-tab__pane {
    height: 100%;
  }
}

.home-page {
  height: 100%;
  .btn-wrapper {
    position: absolute;
    right: 0;
    top: 0;
    width: 86px;
    height: 44px;
    background: #fff;
    display: flex;
    align-items: center;
    .geek-icon {
      flex: 1;
      text-align: center;
      font-size: 18px;
    }
    &::before {
      content: "";
      width: 20px;
      height: 44px;
      position: absolute;
      left: -20px;
      top: 0;
      background: linear-gradient(to right, rgba(255,255,255,0), #fff);
    }
  }
}
</style>
